
<?php

defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$uniacid = $_SESSION['uniacid'];
$mid = $_SESSION['uid'];
$return['setting']=$basic=$this->plugin_setting('basic');
$return['advs']=$basic['image'];
$return['basic']=$basic;
if($_RQ['op']=='main'){
	/*******main*******/
	//所有活动
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['cid']){
		$params['categoryid']=intval($_RQ['cid']);
		$return['params']['cid']=intval($_RQ['cid']);
	}
	if($_RQ['keyword']){
		$params['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$fields=array('id','categoryid','uniacid','title','desc','image','status','goodsid','agio','goodsnum','sales','teamnum','groupnum','endtime','starttime','isindex','ishot','displayorder','single','createtime');
	$groups=pdo_getslice('jy_aligroup_groups',$params,array($pindex,$psize),$total,$fields,'','id desc, displayorder desc');
	$groups_count=count($groups);
	if($groups){
		foreach($groups as &$item){
			$goods=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			
			if($item['agio']!=0){
				$item['groupsprice']=price($goods['price']*$item['agio']/100);
				
			}else{
				$item['groupsprice']=price($goods['price']);
			}
			$item['goods']=$goods;
			$item['endstatus']=$item['starttime']<time() ? $item['endtime']>time()? 1 : 2 : 0;
			$item['statustitle']=$item['starttime']<time() ? $item['endtime']>time()? '去拼团' : '已结束' : '未开始';
			$item['ordernum'] = pdo_count('jy_aligroup_groups_order',array('status' => array(1,2,3,4), 'groupid' => $item['id'], 'uniacid' => $_SESSION['uniacid']));
			$item['goodsnum']=$item['goodsnum']?:100;
			$item['lastnum']=$item['goodsnum']-$item['ordernum'];
		}
	}
	
	$return['groups']=$groups;
	$return['list']=$groups;
	$return['groups_count']=$groups_count;
	$return['sharedata']=array(
			'title'=>$basic['share_title']?$basic['share_title']:'拼团列表',
			'desc'=>$basic['share_desc']?$basic['share_desc']:'拼团列表-在线拼团商城！',
			'link'=>custom_url('jy_aligroup/group//fromuser='.$_SESSION['uid'],true),
			'imgUrl'=>tomedia($basic['share_image'])
	);
	set_html('title',$basic['title']?:'拼团列表');
	exi($return);
}